﻿/**************************************************************
 *
 * 唯一标识：ec95aba9-88df-40c4-a0eb-aee591a45702
 * 命名空间：Sgr.OrganizationAggregate
 * 创建时间：2023/8/3 10:05:29
 * 机器名称：DESKTOP-S0D075D
 * 创建者：antho
 * 电子邮箱：fengqinhua2016@163.com
 * 描述：
 *
 **************************************************************/

using Sgr.Domain.Entities;
using Sgr.Domain.Managers;
using Sgr.Exceptions;
using Sgr.UPMS.Domain.Users;

namespace Sgr.UPMS.Domain.Organizations
{
    /// <summary>
    /// 领域服务：组织机构管理
    /// </summary>
    public interface IOrganizationManage : ITreeNodeManage<Organization, long>
    {
        /// <summary>
        /// 创建新的组织机构
        /// </summary>
        /// <param name="newId"></param>
        /// <param name="name"></param>
        /// <param name="staffSizeCode"></param>
        /// <param name="remarks"></param>
        /// <param name="parentId"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        Task<Organization> CreateNewAsync(
            long? newId,
            string name,
            string staffSizeCode,
            string? remarks,
            long? parentId,
            CancellationToken cancellationToken = default);

        /// <summary>
        /// 创建邀请链接
        /// </summary>
        /// <param name="organizationId">组织标识</param>
        /// <param name="validityPeriod">有效期限</param>
        /// <param name="usageLimit">可用次数</param>
        /// <param name="description">描述信息</param>
        /// <param name="cancellationToken">取消令牌</param>
        /// <returns></returns>
        Task<OrganizationInvitation> CreateInvitationAsync(
            long organizationId,
            TimeSpan validityPeriod,
            int usageLimit = -1,
            string? description = null,
            CancellationToken cancellationToken = default);

        /// <summary>
        /// 验证邀请码并获得组织ID
        /// </summary>
        /// <param name="invitationCode">邀请码</param>
        /// <param name="cancellationToken">取消令牌</param>
        /// <returns></returns>
        Task<InvitationValidationResult> ValidateInvitationAsync(
            string invitationCode,
            CancellationToken cancellationToken = default);

        /// <summary>
        /// 提交组织认证信息
        /// </summary>
        /// <param name="organization"></param>
        /// <param name="usci">统一社会信用代码</param>
        /// <param name="businessLicensePath">营业执照</param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="DomainException"></exception>
        Task SubmitToConfirmed(Organization organization, string usci, string businessLicensePath, CancellationToken cancellationToken = default);

        /// <summary>
        /// 组织注销前审查
        /// </summary>
        /// <param name="organization"></param>
        /// <param name="user"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        Task<DomainRuleCheckResult> CancellationExamination(Organization organization, User user, CancellationToken cancellationToken = default);
    }
}